package yxy.game.pm2.module.chat;

import org.redisson.api.RSet;
import yxy.apple.util.redisson.RedisException;
import yxy.cherry.game.base.redis.RedisManager;
import yxy.game.pm2.bean.module.BaseGameRedisBean;

/**
 * 聊天黑名单热点数据
 * <pre>
 *     定时清除数据程序请看{@link yxy.cherry.gm.task.Chat.CleanChatBlackTask}
 *</pre>
 *
 * @ClassName HotSpotDataModule
 * @Author jingtao-zheng
 * @Date 2022/8/15 18:56
 * @Version 1.0
 **/
public class HotSpotDataModule extends BaseGameRedisBean {

    /**
     * 热点数据添加
     */
    static public void addHotSpotData(String playerCode){
        try {
            RSet<Object> set = RedisManager.client(redis()).getSet(key());
            set.add(playerCode);
        } catch (RedisException e) {
            e.printStackTrace();
        }
    }

    /**
     * 热点数据获取
     */
    static public RSet<String> getHotSpotData(){
        try {
            RSet<String> set = RedisManager.client(redis()).getSet(key());
            return set;
        } catch (RedisException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 热点数据移除
     */
    static public void removeHotSpotData(String playerCode){
        try {
            RSet<Object> set = RedisManager.client(redis()).getSet(key());
            set.remove(playerCode);
        } catch (RedisException e) {
            e.printStackTrace();
        }
    }


    //===================================redis
    static public String key() {
        return String.format("CHAT:HOTSPOTDATA");
    }

    @Override
    public String lockKey() {
        return String.format("lock:%s", key());
    }
}
